<?php

namespace Biz\Resources\Site;

use Lumen\Http\Resources\Json\Resource;
use Biz\Constants\Site\SiteTrafficConstants;

/**
 * SiteTrafficResource.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class SiteTrafficResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'uid'         => $this->uid,
            'status'      => $this->status,
            'status_name' => SiteTrafficConstants::$StatusNames[$this->status],
            'created_at'  => $this->created_at->getTimestamp(),
            $this->mergeWhen($this->relationLoaded('translations'), [
                'translations' => $this->getSiteTrafficTranslationsResourceCollection(),
            ]),
        ];
    }

    /**
     * Get app resource.
     *
     * @return SiteTrafficTranslationsResourceCollection|null
     */
    public function getSiteTrafficTranslationsResourceCollection()
    {
        if ($this->relationLoaded('translations')) {
            return new SiteTrafficTranslationsResourceCollection($this->translations);
        }

        return null;
    }
}
